﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace BBPA.BLL
{
    public partial class Orders_Stat
    {
       // FieldInfo fildInfo
        /// <summary>
        /// 统计数据+1
        /// </summary>
        /// <param name="columnName_">列名</param>
        //public static void Increase(EnumHelper.Stat columnName_) { Increase(columnName_, "1"); }
        public static void Increase(FieldInfo  columnName_) { Increase(columnName_, "1"); }
        /// <summary>
        /// 统计数据+N
        /// </summary>
        /// <param name="columnName_">列名</param>
        /// <param name="addNum_">要加的N</param>
        //public static void Increase(EnumHelper.Stat columnName_, object addNum_)
        public static void Increase(FieldInfo  columnName_, object addNum_)
        {
            
            if (addNum_ == null) return;
            string columnNameStr = columnName_.Name.ToString();

            DAL.Orders_Stat dal = new DAL.Orders_Stat();
            BLL.Orders_Stat bll = new BLL.Orders_Stat();
            Model.Orders_Stat model_Day = new Model.Orders_Stat(), model_Week = new Model.Orders_Stat(), model_Month = new Model.Orders_Stat();
            model_Day.DateType = 0; model_Week.DateType = 1; model_Month.DateType = 2;
            int id_Day = 0, id_Week, id_Month;
            //
            List<Model.Orders_Stat> listModel_Day =bll. GetModelList("datediff(day,[DateFrom],getdate())=0 and DateType=0");
            if (listModel_Day.Count == 0) id_Day = bll.Add(model_Day);
            else id_Day = listModel_Day[0].id;
            dal.Increase(id_Day, columnNameStr, addNum_);
            //
            List<Model.Orders_Stat> listModel_Week = bll.GetModelList("datediff(week,[DateFrom],getdate())=0 and DateType=1");
            if (listModel_Week.Count == 0) id_Week = bll.Add(model_Week);
            else id_Week = listModel_Week[0].id;
            dal.Increase(id_Week, columnNameStr, addNum_);
            //
            List<Model.Orders_Stat> listModel_Month = bll.GetModelList("datediff(month,[DateFrom],getdate())=0 and DateType=2");
            if (listModel_Month.Count == 0) id_Month = bll.Add(model_Month);
            else id_Month = listModel_Month[0].id;
            dal.Increase(id_Month, columnNameStr, addNum_);

        }
    }
}
